package org.bbelovic.devel.futureexample;

import java.util.concurrent.Callable;

import org.bbelovic.devel.algorithms.recursive.RecursiveAlgorithm;

public class FutureExampleService<I, O> implements Callable<FutureExampleResult<O>> {

	private final RecursiveAlgorithm<I, O>fibonacci;

	public FutureExampleService(RecursiveAlgorithm<I, O> algorithm) {
		this.fibonacci = algorithm;
	}

	@Override
	public FutureExampleResult<O> call() throws Exception {
		final long start = System.currentTimeMillis();
		final O result = fibonacci.compute();
		final long end = System.currentTimeMillis();
		return new FutureExampleResult<O>(result, end-start);
		
	}	
}
